package com.xiaode.controller.app.student.example;

import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.kit.Ret;
import com.xiaode.common.anotation.JSONArrayString;
import com.xiaode.common.model.Student;
import com.xiaode.util.apidoc.annotation.Api;
import com.xiaode.util.apidoc.annotation.ApiOper;
import com.xiaode.util.apidoc.annotation.ApiPara;

import javax.validation.constraints.Size;
import java.util.Date;

/**
 * 榜样相关服务
 *
 * @Author: 刘绪
 * @Date: 2022/3/11
 */
@Api("学生榜样相关服务")
@Path("/sExample")
@EnableCORS
public class ExampleController extends Controller {
    @Inject
    ExampleService service;

    /**
     * 查询学生的榜样信息
     */
    @ApiOper("查询学生榜样信息")
    public void findBindExample(
    		@ApiPara(value = "studentId", notes = "学生id") Integer studentId,
    		@ApiPara(value = "state", notes = "1.审核中,2.组长待审核,3.导师审核不通过,4.组长审核通过 5.组长拒绝") Integer state) throws Exception {
    	Integer userId = getAttr("userId");
    	Ret ret = service.findBindExample(userId, studentId, state);
        renderJson(ret);
    }

    /**
     * 通过id获取榜样详情
     */
    @ApiOper("通过id获取榜样详情")
    public void findExample(@Size @ApiPara(value = "exId", notes = "榜样id") Integer exId) throws Exception {
        Ret ret = service.findExample(exId);
        renderJson(ret);
    }

    /**
     * 修改榜样(如果没有审核或者没有通过)
     *
     * @param exId    榜样id
     * @param name    榜样名称
     * @param label   标签
     * @param brief   简介
     * @param keyWord 关键词
     * @throws Exception
     */
    @ApiOper("修改榜样")
    public void updateExample(
            @ApiPara(value = "exId", notes = "榜样id") Integer exId,
            @ApiPara(value = "name", notes = "榜样名称") String name,
            @ApiPara(value = "label", notes = "标签") String label,
            @ApiPara(value = "brief", notes = "简介") String brief,
            @ApiPara(value = "reason", notes = "选择原因") String reason,
            @ApiPara(value = "pic",notes = "榜样图片")String pic,
            @ApiPara(value = "characterType", notes = "人物类型") Integer characterType,
            @ApiPara(value = "keyWord", notes = "关键词") String keyWord) throws Exception {
        Student student = getAttr("user");
        Ret ret = service.updateExample(pic, exId, name, label, brief, keyWord, student.getId(), reason, characterType);
        renderJson(ret);
    }


    /**
     * 添加新的榜样
     *
     * @param name    榜样名称
     * @param label   标签
     * @param brief   简介
     * @param keyWord 关键词
     * @throws Exception
     */
    @ApiOper("添加新的榜样")
    public void addExample(
            @Size(max = 20) @ApiPara(value = "name", notes = "榜样名称") String name,
            @ApiPara(value = "label", notes = "标签") String label,
            @Size(min = 50,max = 200) @ApiPara(value = "brief", notes = "简介") String brief,
            @Size(max = 300) @ApiPara(value = "reason", notes = "选择原因") String reason,
            @Size @ApiPara(value = "characterType", notes = "人物类型") Integer characterType,
            @Size @ApiPara(value = "pic",notes = "榜样图片url")String pic,
            @ApiPara(value = "keyWord", notes = "关键词") String keyWord) throws Exception {
        Student student = getAttr("user");
        Ret ret = service.addExample(pic, name, label, brief, keyWord, student.getId(), reason, characterType);
        renderJson(ret);
    }


    /**
     * 学生添加/修改榜样任务
     *
     * @param tasks 任务名称
     */
    @ApiOper("学生添加榜样任务")
    public void addExampleTask(
            @JSONArrayString @ApiPara(value = "tasks", notes = "[{taskId:taskId,content:content}]") String tasks,
            @ApiPara(value = "date",notes = "起始日期")Date startDate,
            @ApiPara(value = "date", notes = "截止日期") Date date) throws Exception {
        Student student = getAttr("user");
        Ret ret = service.addExampleTask(student.getId(), tasks,startDate, date);
        renderJson(ret);
    }

    @ApiOper("查询学生添加的榜样任务")
    public void getExampleTask(@ApiPara(value = "studentId", notes = "学生id") Integer studentId) throws Exception {
    	Integer userIdMy = getAttr("userId");
        Ret ret = service.getExampleTask(userIdMy, studentId);
        renderJson(ret);
    }

    /**
     * 删除榜样任务
     *
     * @param taskId 任务id
     * @throws Exception
     */
//    @ApiOper("删除榜样任务")
//    public void delExampleTask(@Size @ApiPara(value = "taskId", notes = "任务id") Integer taskId) throws Exception {
//        Student student = getAttr("user");
//        Ret ret = service.delExampleTask(student.getId(), taskId);
//        renderJson(ret);
//    }


    /**
     * 展示学生榜样
     *
     * @param curPage  当前页
     * @param pageSize 每页大小
     * @throws Exception
     */
    @ApiOper("展示学生可选择的榜样")
    public void exhibitExamplePage(
            @Size(min = 1) @ApiPara(value = "curPage", notes = "当前页") Integer curPage,
            @Size(min = 1) @ApiPara(value = "pageSize", notes = "每页大小") Integer pageSize) throws Exception {
        Student student = getAttr("user");
        Ret ret = service.exhibitExample(student.getId(), curPage, pageSize);
        renderJson(ret);
    }

    /**
     * 查询默认榜样的默认任务
     *
     * @throws Exception
     */
    @ApiOper("查询默认榜样的默认任务")
    public void findDefaultTaskByExampleId(@Size(min = 1) @ApiPara(value = "exId", notes = "榜样id") Integer exId) throws Exception {
        Ret ret = service.findDefaultTaskByExampleId(exId);
        renderJson(ret);
    }

    /**
     * 查询绑定榜样的学生信息
     */
    @ApiOper("查询绑定某榜样的学生信息")
    public void findStusByExample(@Size @ApiPara(value = "exName", notes = "榜样名称") String exName,
                                  @Size(min = 1) @ApiPara(value = "page", notes = "当前页") Integer page,
                                  @Size(min = 1) @ApiPara(value = "limit", notes = "每页数量") Integer limit) throws Exception {
        Student student = getAttr("user");
        Ret ret = service.findStusByExample(student.getId(), exName,page,limit);
        renderJson(ret);
    }
    
    
    /**
     * 学生 查询榜样任务过期时间,查询榜样是否需要完善
     */
    @ApiOper("查询榜样任务过期时间,查询榜样是否需要完善")
    public void findExampleDeadLine() throws Exception {
        Student student = (Student)getAttr("user");
        Ret ret = service.findExampleDeadLine(student.getId());
        renderJson(ret);
    }

}